classdef OSXopenOptions < handle
    properties (SetAccess = private)
        openInterestMap = containers.Map( );
        call_string = '';
        put_string = '';
    end
    
    methods
        %%
        function obj = OSXopenOptions()
      
            %Get data from Oslo Stock Exchange web page
            osxLink = 'http://oslobors.no/ob_eng/markedsaktivitet/derivateUndOverview?newt__ticker=OBX&newt__isin=NO0000000021';
            data_string = urlread( osxLink );
            data_string = data_string( strfind( data_string,'<!-- Main area content: START -->' ):...
                strfind( data_string,'<!-- Main area content: END -->' ) );

            %Extract open interests
            tempInd = 1;
            while true
                tick_ind = strfind(data_string(tempInd:end), 'OBX1' );
                if isempty( tick_ind );
                    return;
                end
                tick_ind(2) = tick_ind(2)+tempInd;
                ticker = data_string( tick_ind(2)-1:tick_ind(2)+strfind(data_string(tick_ind(2):tick_ind(2)+10),'<')-2 );
                if ticker(5) < 'M' && length(ticker)>5
                    obj.call_string = strcat( obj.call_string, ticker, '.OMFE&' );
                elseif length(ticker)>5
                    obj.put_string = strcat( obj.put_string, ticker, '.OMFE&' );
                end
                c11_ind = strfind(data_string(tick_ind(2):tick_ind(2)+400),'c11');
                start_ind = strfind(data_string(tick_ind(2)+c11_ind:tick_ind(2)+c11_ind+20),'>');
                stop_ind = strfind(data_string(tick_ind(2)+c11_ind:tick_ind(2)+c11_ind+20),'<');
                num_str = data_string(tick_ind(2)+c11_ind+start_ind(1):tick_ind(2)+c11_ind+stop_ind(1)-2);

                if length(ticker) > 5
                    obj.openInterestMap( ticker ) = str2double( strrep( num_str,',' ,'' ) );
                end
                tempInd = tick_ind(2);
            end

        end
    end
    
end